﻿using EasyERP_DAL;
using EasyERP_DAL.Base;
using EasyERP_Model;
using System;
using System.Data;
using System.Text;

namespace EasyERP_BLL.Base
{
    /// <summary>
    /// 子代码业务逻辑类
    /// </summary>
    public class B_Minor_BLL
    {
        /// <summary>
        /// 声明只读子代码数据访问类对象
        /// </summary>
        private B_Minor_DAL Minor_DAL = new B_Minor_DAL();

        #region 查询子代码信息
        /// <summary>
        /// 查询子代码信息
        /// </summary>
        /// <param name="model">子代码实体对象</param>
        /// <returns>返回查询表</returns>
        public DataTable Get_B_Minor(B_Minor model)
        {
            try
            {
                return Minor_DAL.Get_B_Minor(model);
            }
            catch (Exception ex)
            {
                B_Message_BLL.MessageCaveat(ex);        //弹出异常对话框
                return null;
            }
        }
        #endregion

        #region 添加子代码信息
        /// <summary>
        /// 添加子代码信息
        /// </summary>
        /// <param name="model">子代码实体对象</param>
        /// <returns>返回True：成功；返回False：失败</returns>
        public bool Insert_B_Minor(B_Minor model)
        {
            if (string.IsNullOrWhiteSpace(model.major_cd))      //主代码编号为空
            {
                B_Message_BLL.MessageCaveat("2001");            //弹出提示框
                return false;
            }
            if (string.IsNullOrWhiteSpace(model.minor_cd))      //子代码编号为空
            {
                B_Message_BLL.MessageCaveat("2004");            //弹出提示框
                return false;
            }

            if (string.IsNullOrWhiteSpace(model.minor_nm))      //子代码名称为空
            {
                B_Message_BLL.MessageCaveat("2005");            //弹出提示框
                return false;
            }

            //保存前验证数据是否存在
            if (Minor_DAL.Exists(model))                      //存在
            {
                B_Message_BLL.MessageCaveat("1001");            //弹出提示框
                return false;
            }

            try
            {
                return Minor_DAL.Insert_B_Minor(model);
            }
            catch (Exception ex)
            {
                B_Message_BLL.MessageCaveat(ex);
                return false;
            }
        }
        #endregion

        #region 删除子代码信息
        /// <summary>
        /// 删除子代码信息
        /// </summary>
        /// <param name="model">子代码实体对象</param>
        /// <returns>返回True：成功；返回False：失败</returns>
        public bool Delete_B_Minor(B_Minor model)
        {
            if (string.IsNullOrWhiteSpace(model.major_cd))      //主代码编号为空
            {
                B_Message_BLL.MessageCaveat("2001");            //弹出提示框
                return false;
            }
            if (string.IsNullOrWhiteSpace(model.minor_cd))      //子代码编号为空
            {
                B_Message_BLL.MessageCaveat("2005");            //弹出提示框
                return false;
            }

            //删除前验证数据是否存在
            if (Minor_DAL.Exists(model))                      //要删除的不存在
            {
                try
                {
                    return Minor_DAL.Delete_B_Minor(model);
                }
                catch (Exception ex)
                {
                    B_Message_BLL.MessageCaveat(ex);
                    return false;
                }
            }
            B_Message_BLL.MessageCaveat("1002");                //弹出提示框
            return false;
        }
        #endregion

        #region 修改子代码信息
        /// <summary>
        /// 修改子代码信息
        /// </summary>
        /// <param name="model">子代码实体对象</param>
        /// <returns>返回True：成功；返回False：失败</returns>
        public bool Update_B_Minor(B_Minor model)
        {
            if (string.IsNullOrWhiteSpace(model.major_cd))      //主代码编号为空
            {
                B_Message_BLL.MessageCaveat("2001");            //弹出提示框
                return false;
            }
            if (string.IsNullOrWhiteSpace(model.minor_cd))      //子代码编号为空
            {
                B_Message_BLL.MessageCaveat("2005");            //弹出提示框
                return false;
            }

            if (string.IsNullOrWhiteSpace(model.minor_nm))      //子代码名称为空
            {
                B_Message_BLL.MessageCaveat("2006");            //弹出提示框
                return false;
            }

            //修改前验证数据是否存在
            if (Minor_DAL.Exists(model))                      //要修改的不存在
            {
                try
                {
                    return Minor_DAL.Update_B_Minor(model);
                }
                catch (Exception ex)
                {
                    B_Message_BLL.MessageCaveat(ex);
                    return false;
                }
            }
            B_Message_BLL.MessageCaveat("1003");                //弹出提示框
            return false;
        }
        #endregion

        #region 根据主代码查询子代码
        /// <summary>
        /// 根据主代码查询子代码
        /// </summary>
        /// <param name="model">子代码实体类</param>
        /// <returns>查询的子代码信息</returns>
        public DataTable Get_Minor_nm(B_Minor model)
        {
            try
            {
                return Minor_DAL.Get_Minor_nm(model);
            }
            catch (Exception ex)
            {
                B_Message_BLL.MessageCaveat(ex);        //弹出异常对话框
                return null;
            }
        }
        #endregion

        #region 查询子代码信息,用于参照窗体FrmPopMinor
        /// <summary>
        /// 查询子代码信息,用于参照窗体FrmPopMinor
        /// </summary>
        /// <param name="model">子代码实体对象</param>
        /// <returns>返回查询表</returns>
        public DataTable Get_B_Minor_Pop(B_Minor model)
        {
            try
            {
                return Minor_DAL.Get_B_Minor_Pop(model);
            }
            catch (Exception ex)
            {
                B_Message_BLL.MessageCaveat(ex);        //弹出异常对话框
                return null;
            }
        }
        #endregion
    }
}
